using System.Collections.Generic;
using System.Linq;
using tomenglertde.SetupProject.Model;

namespace tomenglertde.SetupProject.ViewModel
{
    public abstract class SetupItem
    {
        private readonly NodeEntity _node;
        private readonly SetupProjectViewModel _project;

        protected SetupItem(NodeEntity node, SetupProjectViewModel project)
        {
            _node = node;
            _project = project;
        }

        public abstract string Id
        {
            get;
            set;
        }

        public IEnumerable<string> OwnerIds
        {
            get
            {
                return _project.Hierarchy.Where(h => h.Id == Id).Select(h => h.Owner).Where(id => id != "_UNDEFINED");
            }
        }

        public IEnumerable<string> ChildIds
        {
            get
            {
                return _project.Hierarchy.Where(h => h.Owner == Id).Select(h => h.Id).Where(id => id != "_UNDEFINED");
            }
        }

        public NodeEntity Node
        {
            get
            {
                return _node;
            }
        }

        public SetupProjectViewModel Project
        {
            get
            {
                return _project;
            }
        }

        public void Remove()
        {
            Node.Parent.Children.Remove(Node);
        }
    }
}